home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
fortn404.zip
/
FORTUNE.DOC
< prev
next >
Wrap
Text File
|
1994-04-23
|
15KB
|
318 lines
FORTUNE.DOC
04/23/94
The FORTUNE.EXE program adds some tuning features to the DOS FOR command (FOR
tune, fortune, what the heck). These features can in some way be applied to
commands accepting regular DOS wildcards. Features include:
* Results of command are written to a batch file which you can review before
you run it. Lets you subsequently edit it if desired and lets you see
exactly what commands will happen when you run it.
* Ability to imbed redirection indicators in a command (see next example).
* Ability to separate the file name and file extension. For example:
FORTUNE IN (*.TXT) DO SORT %[ %A %] %1*.SOR
* Ability to identify individual characters in the the file name and extension.
For example:
FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
* Ability to specify a character other than "%" for the delimiter so you can
avoid worrying about different syntax in batch command vs command line
* Ability to have batch file pause after each command so results can be
reviewed.
* Ability to specify incrementation in the file names. For example:
FORTUNE IN (*.TXT) /+2 DO COPY %A %1*.%0001
* Ability to specify multiple statements on one command line.
* Ability to process children subdirectories (/S option) at same time. For
example:
FORTUNE IN (\*.TXT) /S DO COPY %A D:\BACKUPS
FORTUNE *.BAT /S DEL %A
* Ability to exclude up to 10 file specifications from consideration.
The DOS FOR command:
Quite a few DOS users are unaware of the DOS FOR command. It allows you to do a
single command over a series of files and provides an easy way to use wildcards
with commands that don't accept them. For example, if you want to type a number
of files to your screen, you can say something like:
FOR %A IN (*.TXT) DO TYPE %A
DOS looks at your IN specification and figures out what file names are covered
by that request. The request can include path information if desired and can
have multiple specification (e.g. "...IN (*.TXT \BAT\*.DOC)...").
FOR then substitutes the file name itself in for whatever variable you specify
in the first parameter after "FOR" ("%A" here). This variable is a single
character (A to Z) preceded by a single percent sign (%). (If FOR is used in a
batch command, you have to use two percent signs (%%) instead.)
FOR then looks at the command following the keyword "DO" and executes that
command. If it finds the variable name in the command, it substitutes the name
of the file for that variable.
So, in the above example, if you had three *.TXT files--ABLE.TXT, BAKER.TXT,
and CHARLIE.TXT--and you ran the command, it would actually do three commands
for you:
TYPE ABLE.TXT
TYPE BAKER.TXT
TYPE CHARLIE.TXT
All in all, FOR is a *very* useful command. There are also some DOS tricks that
you can use to make the command even more useful but, frankly, I always forget
the tricks. (If someone would like to e-mail them to me, I'll throw them in
here.) In any case, even past the tricks, the FORTUNE command provides even more
features.
FORTUNE wildcards and special characters:
The FORTUNE.EXE program extends the functionality of the DOS FOR command by
providing ways of splitting up the parts of the file name and manipulating the
parts. For example, someone in my office had a mess of files that had to be
renamed as an open parenthesis, followed by the first six characters of the file
name, followed by a close parenthesis. Not too terrible to handle with my text
editor but it hadn't occurred to her. Using FORTUNE, however, it's pretty easy:
FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
And then you run the newly-created batch file (DOIT.BAT).
Similarly, someone wanted me to rename a mess of files so they had sequential
names. I had to write a program to handle it. Definitely beyond his
capabilities. Again, using FORTUNE it's pretty easy:
FORTUNE IN *.TXT DO RENAME %A %1*.%0001
And again you run the DOIT.BAT file.
Within the command (DO command), FORTUNE allows you to include a number of
indicators. The character which indicates that it's a special character is
typically "%" but you can change this with the /VAR=char option in FORTUNE.
(You can also set the default by using the CONFIGWS program.) All of the
examples here use the default /VAR=% setting.
NOTE TO 4DOS USERS: 4DOS automatically translates %x characters even if used on
the command line. As such, 4DOS users *have* to use a different /VAR=x setting
to use FORTUNE. FORTUNE detects that you are running 4DOS and typically changes
the default /VAR=x to /VAR=@. This default can be changed by using the CONFIGWS
program.
In many cases, the indicators are case sensitive; there's a difference between
%p and %P. Typically, the lowercase variants are cumulative. %P gives you just
the path whereas %p throws in the drive information too.
%a translates into the entire file name (begins with drive,
colon, \, path, \, file root, ., file extension).
Use %R.%E if you want the filename without the drive/path info
%D translates into the drive (not followed by :)
%d translates into the drive (followed by :)
%P translates into path (not preceded or followed by \)
%p translates into path (begins with drive, colon, \, path, \)
%R translates into file name root
%r translates into file name root (begins with drive, colon, \,
path, \)
%E translates into file name extension
%e translates into file name extension (begins with drive, colon,
\, path, \, file name root, .)--same as %a
%1 to %8 characters 1 to 8 in the file name root
%X to %Z characters 1 to 3 in file name extension (case insignicant;
%X is the same as %x)
Standard DOS wildcards are supported within the file name. So %1* will give you
all characters in the file name root, %2* will give you all characters beginning
with the second character. "?" is also supported. Wildcards outside of the
special indicators work as expected ("...DO RENAME %A %1*.%X*" works
identically to "...DO RENAME %A *.*").
All other characters in the command string are passed as given.
Using the above characters, if you have two files C:\AUTOEXEC.BAT and
D:\WAYNE\MYSTUFF.TXT, the various codes above translate as:
C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%A C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%D C D
%d C: D:
%P (null) WAYNE
%p \ D:\WAYNE\
%R AUTOEXEC MYSTUFF
%r C:\AUTOEXEC D:\WAYNE\MYSTUFF
%E BAT TXT
%e C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%1 A M
%2 U Y
%3 T S
%4 O T
%5 E U
%6 X F
%7 E F
%8 C (null)
%X B T
%Y A X
%Z T T
Special translations:
%[ translates into <
%] translates into >
%0nnnn incrementer field (where "nnnn" is any number of digits;
translates into a numeric field which has the same number of
digits; the first number will be the value of "nnnn" and
subsequent files will be incremented by the value specified in
the /+n or /-n parameter (defaults to /+1)
Syntax:
FORTUNE { IN (set) | IN filespec | /IN (set) | /IN filespec | filespec }
[ /AS filename ] [ /OV